home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / spacewar / logoff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-31  |  2.6 KB  |  125 lines

  1. /*
  2.  * Spacewar - logoff a player:
  3.  *        reset tty modes
  4.  *        close the tty I/O channel
  5.  *         terminate (signal) the play and read processes
  6.  *        clear out the login structure
  7.  *
  8.  * Copyright 1984 obo Systems, Inc.
  9.  * Copyright 1984 Dan Rosenblatt
  10.  */
  11.  
  12. #include <signal.h>
  13. #include "spacewar.h"
  14. #include "universe.h"
  15. #include "login.h"
  16.  
  17. #ifdef BSD
  18. #    include <sgtty.h>
  19. #else /* VMS SYSIII SYSV */
  20. #ifdef VMS
  21. #    include <ssdef.h>
  22. #else /* SYSIII SYSV */
  23. #    include <sys/types.h>
  24. #    include <sys/ioctl.h>
  25. #    include <termio.h>
  26. #endif /* VMS SYSIII SYSV */
  27. #endif /* BSD VMS SYSIII SYSV */
  28.  
  29. VOID logoff(plogin)
  30. register struct login *plogin;
  31. {
  32. #ifdef VMS
  33.     int i;
  34. #endif /* VMS */
  35.     extern int errno;
  36.  
  37. #ifdef DEBUG
  38.     DBG("logoff(#%d/%s)\n",plogin-loginlst,plogin->ln_name);
  39. #endif
  40.  
  41.     /* remove from universe if playing */
  42.     if (plogin->ln_play.ip_ptr) unplay(plogin);
  43.  
  44.     /*****************/
  45.     /* set tty modes */
  46.     /*****************/
  47. #ifdef BSD
  48.     {
  49.     struct sgttyb tmode;
  50.  
  51.     if (gtty(plogin->ln_tty,&tmode)) {
  52.         perror("gtty");
  53.         goto sigh;    /* horrendous */
  54.     }
  55.  
  56.     /* reset echo and no cbreak mode */
  57.     /* (too bad the previous states weren't saved)  */
  58.     tmode.sg_flags &= ~CBREAK;
  59.     tmode.sg_flags |= ECHO;
  60.  
  61.     if (stty(plogin->ln_tty,&tmode)) {
  62.         perror("stty");
  63.         goto sigh;    /* horrendous */
  64.     }
  65.     }
  66. #else /* VMS SYSIII SYSV */
  67. #ifndef VMS
  68.     {
  69.     struct termio tmode;
  70.  
  71.     if (ioctl(plogin->ln_tty,TCGETA,&tmode)) {
  72.         perror("ioctl TCGETA");
  73.         goto sigh;    /* horrendous */
  74.     }
  75.  
  76.     /* reset echo and erase/kill edit processing */
  77.     /* (too bad the previous states weren't saved)  */
  78.     tmode.c_lflag |= ICANON+ECHO+ECHOE+ECHOK+ECHONL;
  79.     tmode.c_cc[VEOF] = CEOF;
  80.     tmode.c_cc[VEOL] = CNUL;
  81.  
  82.     if (ioctl(plogin->ln_tty,TCSETA,&tmode)) {
  83.         perror("ioctl TCSETA");
  84.         goto sigh;    /* horrendous */
  85.     }
  86.     }
  87. #endif /* VMS SYSIII SYSV */
  88. #endif /* BSD VMS SYSIII SYSV */
  89.  
  90.     /* close the player's terminal and kill the read and play processes */
  91. sigh:
  92. #ifdef VMS
  93.     output(plogin,0,0,0);
  94.     output(plogin,'C',0,"ShUtDoWn");
  95.     output(plogin,0,0,0);
  96.     if ((i=sys$delmbx(plogin->ln_tty)) != SS$_NORMAL) {
  97.         perror("delete mlbx 1");
  98. #ifdef DEBUG
  99.         VDBG("logoff delmbx()=%d, errno=%d\n",i,errno);
  100. #endif
  101.     }
  102.     if ((i=sys$dassgn(plogin->ln_tty)) != SS$_NORMAL) {
  103.         perror("dassgn mlbx 1");
  104. #ifdef DEBUG
  105.         VDBG("logoff dassgn()=%d, errno=%d\n",i,errno);
  106. #endif
  107.     }
  108. #else /* BSD SYSIII SYSV */
  109.     if (close(plogin->ln_tty))
  110.         perror("close");
  111.     if (kill(plogin->ln_readpid,SIGTERM))
  112.         perror("kill readsw");
  113.     else
  114.         wait(0);
  115.     if (kill(plogin->ln_playpid,SIGTERM))
  116.         perror("kill playsw");
  117. #endif /* VMS BSD SYSIII SYSV */
  118.  
  119.     /* reset the login entry */
  120.     binit((char *)plogin,sizeof(*plogin));
  121. #ifdef DEBUG
  122.     VDBG("logoff return\n");
  123. #endif
  124. }
  125.